home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3055 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  50 lines

  1. Path: newsfeed.internetmci.com!iol!usenet
  2. From: mat8033@iol.ie (Stuart Mc Bride)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Getting the system time and date
  5. Date: Mon, 22 Jan 1996 08:01:12 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4duk43$8ql@barnacle.iol.ie>
  8. References: <tate.1.002C7F92@netwest.com>
  9. NNTP-Posting-Host: dialup-103.dublin.iol.ie
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. tate@netwest.com (Tate Griffin) wrote:
  13.  
  14. >How do I get the current time and date from a PC using C++?
  15.  
  16. Very easy, it's in the help file of BC3.1, but if you don't have
  17. that, here's how to do it:
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. void main()
  23.     {
  24.     struct dostime_t t;
  25.     struct dosdate_t d;
  26.  
  27.     _dos_gettime(&t);
  28.     _dos_getdate(&d);
  29.  
  30.     printf("The date and time are: ");
  31.     printf("%2d:%02d:%02d.%02d   %d/%d/%d\n",t.hour,
  32.               t.minute,t.second,t.hsecond,d.day,d.month,
  33.              d.year);
  34.  
  35.     return;
  36.     }
  37.  
  38. As you can see, the functions _dos_gettime and _dos_getdate
  39. store the time and date in predefined structs, and can be read
  40. as demonstrated in the example. This reads the dos clock,
  41. there's other functions to read the system clock if you really
  42. want to. Hope that helps.
  43.  
  44.  
  45. --- Stuart ---    mat8033@iol.ie
  46.                   c2smcbri@compapp.dcu.ie
  47.  
  48.    http://www.compapp.dcu.ie/~c2smcbri
  49.  
  50.